<template>
  <div class="sku-popup" v-if="proData.length">
    <van-popup v-model="isShow" closeable position="bottom" round>
      <div class="skupop-header">
        <div class="goods-info">
          <img :src="`${baseURL}/jd_card/goods/${proData[0].gpic}`" alt="" />
        </div>
        <div class="sku-spec">
          <div class="goods-sku">
            <span class="sku-price">￥{{ proData[0].gprice }}</span>
          </div>
          <div class="sku-selected">
            <span class="s1">已选</span>
            <span class="s2">{{ selected }}</span>
          </div>
        </div>
      </div>
      <div class="skupop-body">
        <div class="sku-row-contanier">
          <div class="sku-row van-hairline--bottom">
            <div class="sku-row-tit">
              <span>单张面值</span>
            </div>
            <div
              class="sku-item"
              v-for="(item, i) of proData"
              :key="i"
              :class="{ 'sku-item--active': i == isActive }"
              @click="item_actived(i, item.types)"
            >
              <div class="sku-item-value">{{ item.types }}</div>
            </div>
          </div>
        </div>
        <div class="sku-stepper-stock">
          <div class="sku-stepper-tit">购买数量</div>
          <div class="sku-stepper">
            <button
              type="button"
              class="stepper-minus"
              @click="handleMinus"
            ></button>
            <input
              readonly="readonly"
              inputmode="numeric"
              class="stepper-input"
              v-model="buyNum"
            />
            <button
              type="button"
              class="stepper-plus"
              @click="handlePlus"
            ></button>
          </div>
        </div>
      </div>
      <div class="sku-footer">
        <div class="sku-actions">
          <button>
            <span>加入购物车</span>
          </button>
          <button>
            <span>立即购买</span>
          </button>
        </div>
      </div>
    </van-popup>
  </div>
</template>
<script>
export default {
  props: ['proData'],

  data() {
    return {
      isShow: false,
      isActive: 0,
      selected: "",
      buyNum: 1
    };
  },
  mounted(){
    this.selected=this.proData[0].types;
  },
  methods: {
    item_actived(i, tit) {
      console.log(tit);
      this.isActive = i;
      this.selected = tit;
    },
    handleMinus() {
      if (this.buyNum <= 1) {
        return;
      }
      this.buyNum--;
    },
    handlePlus() {
      console.log(this.proData)
      this.proData.forEach((p)=>{
        if(this.selected==p.types){
            if (this.buyNum >= p.count) {
              this.$toast('当前库存不足')
            return;
          }
          this.buyNum++;
        }
      })
    },
  },
};
</script>
<style lang="scss" scoped>
.skupop-header {
  display: flex;
  padding: 18px;
  position: relative;
  .goods-info {
    img {
      width: 100px;
      height: 100px;
    }
  }
  .sku-spec {
    position: absolute;
    left: 118px;
    bottom: 18px;
    .goods-sku {
      .sku-price {
        color: red;
        font-size: 20px;
      }
    }
    .sku-selected {
      .s1 {
        font-size: 12px;
        color: #ccc;
      }
      .s2 {
        padding-left: 10px;
        font-size: 14px;
      }
    }
  }
}
.skupop-body {
  min-height: 50px;
  max-height: 440px;
  overflow-y: scroll;
  .sku-row-contanier {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    font-size: 14px;
    background: #fff;
    padding: 0 18px;
    .sku-row {
      margin-bottom: 18px;
      .sku-row-tit {
        padding-bottom: 10px;
        font-size: 16px;
        font-weight: bold;
      }
      .sku-item {
        display: inline-flex;
        justify-content: center;
        min-width: 40px;
        margin: 0 12px 12px 0;
        position: relative;
        overflow: hidden;
        color: #323233;
        border-radius: 4px;
        cursor: pointer;
        font-size: 13px;
        line-height: 16px;
        vertical-align: middle;
        &::before {
          position: absolute;
          top: 0;
          left: 0;
          width: 100%;
          height: 100%;
          background-color: #f7f8fa;
          content: "";
        }
        &--active {
          color: #ee0a24;
          &::before {
            background-color: currentColor;
            opacity: 0.1;
          }
        }
        .sku-item-value {
          z-index: 1;
          padding: 8px;
        }
      }
    }
  }
  .sku-stepper-stock {
    padding: 12px 16px;
    overflow: hidden;
    line-height: 30px;
    .sku-stepper-tit {
      font-size: 14px;
      float: left;
    }
    .sku-stepper {
      float: right;
      padding-left: 4px;
      .stepper-minus,
      .stepper-plus {
        position: relative;
        box-sizing: border-box;
        width: 28px;
        height: 28px;
        margin: 0;
        padding: 0;
        color: #323233;
        vertical-align: middle;
        background-color: #f2f3f5;
        border: 0;
        cursor: pointer;
        &--disabled {
          color: #c8c9cc;
          background-color: #f7f8fa;
          cursor: not-allowed;
        }
        &::before,
        &::after {
          position: absolute;
          top: 50%;
          left: 50%;
          background-color: currentColor;
          transform: translate(-50%, -50%);
          content: "";
        }
        &::before {
          width: 50%;
          height: 1px;
        }
      }
      .stepper-plus::after {
        width: 1px;
        height: 50%;
      }
      .stepper-input {
        box-sizing: border-box;
        width: 32px;
        height: 28px;
        margin: 0 2px;
        padding: 0;
        color: #323233;
        font-size: 14px;
        line-height: normal;
        text-align: center;
        vertical-align: middle;
        background-color: #f2f3f5;
        border: 0;
        border-width: 1px 0;
        border-radius: 0;
        -webkit-appearance: none;
      }
    }
  }
}
.sku-footer {
  .sku-actions {
    display: flex;
    flex-shrink: 0;
    padding: 8px 16px;
    button {
      width: 50%;
      position: relative;
      display: inline-block;
      box-sizing: border-box;
      margin: 0;
      padding: 0;
      line-height: 1.2;
      text-align: center;
      cursor: pointer;
      transition: opacity 0.2s;
      height: 40px;
      font-weight: 500;
      font-size: 14px;
      border: none;
      border-radius: 0;
      color: #fff;
      &:first-child {
        background: linear-gradient(to right, #ffd01e, #ff8917);
        border-top-left-radius: 20px;
        border-bottom-left-radius: 20px;
      }
      &:last-child {
        background: linear-gradient(to right, #ff6034, #ee0a24);
        border-top-right-radius: 20px;
        border-bottom-right-radius: 20px;
      }
    }
  }
}
</style>